package com.maretska.java.basic;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;

import org.junit.Test;

public class ArrayLearn {
	double ages[];
	
	// Cara instantiate array
	public void pembuatanArray(){
		ages = new double[20];
		// atau dengan
		int umur[] = new int[3];
		// atau dengan
		int[] usia = new int[3];
	}
	
	@Test
	public void caraMengisiArrayTersebut(){
		String[] nama = {"buddy", "latifah", "barra"};
		double []usia = {23,20,3};
		// Cara mencari nilai tertinggi di dalam ArrayList
		double max = usia[0];
		for (int i =0 ;i<usia.length;i++){
			if (usia[i]>max) max = usia[i];
		}
		System.out.println("Nilai tertinggi : " +max);
	}
	
	@Test
	public void mengisiDenganLoop(){
		int[] arrayList = new int[5];
		for (int i=0;i<arrayList.length;i++){
			arrayList[i] += i;
			System.out.println("Array list bertambah : " +arrayList[i]);
		}
	}
	
	@Test
	public void arrayMultidimensi(){
		// array berukuran 2 x 2
		int[][] arrayList2 = new int[2][2];
			int[][] arrayList3 = {{2,3},
			{3,2}};
			System.out.println(arrayList3[1][1]);
			}
	
	@Test
	// to loop array and print the result
	public void loopArrayDanDiprint(){
		int [] umur = {2, 3, 5, 8};
		for (int ages : umur){
			System.out.println(ages);
		}
	  }
	
	@Test
	// Menggunakkan ArrayList 
	public void arrayListUsed(){
		ArrayList array = new ArrayList();
		array.add("a");
		array.add(1, "B");
		System.out.println("Before Reverse Order : " +array);
	}
	
	@Test
	// Cara mengkopi Object array ke object array yg lain
	public void copy(){
		int[] A = new int[2];
		for (int i=0 ; i<A.length ; i++){
			A[i] += i;
			System.out.println("Sekarang ISI-nya : " +A[i]);
		}
		double[] B = new double[A.length];
		for (int x=0 ; x<B.length ; x++){
			B[x]=A[x]; // Memasukkan Nilai pada Obj A ke Obj B
			System.out.println("Sekarang B ISI-nya : " +B[x]);
		}
	}
	

}

